<script>
import {NEW_BASE_URL} from '@/env'
export default {
  data(){
    return{
      mobile:'',
      code:"",
      list:[{
        name: '',
        checked: false,
      }],
      await: false,
      num:60
    }
  },
  methods:{
    getCode(){
      if(!this.list[0].checked){
        uni.showToast({
          icon:'none',
          title:'请先同意用户服务协议和隐私政策'
        })
        return
      }
      let reg = /^1\d{10}$/
      if(reg.test(this.mobile)){
        uni.request({
          url:`${NEW_BASE_URL}/api/app/login/sendCode/${this.mobile}`,
          method:'GET',
          success(e){
            console.log(e)
          }
        })
        uni.showToast({
          icon:'success',
          title:'验证码已发送请查收'
        })
        this.await = true
        this.setTime()
      }else{
        uni.showToast({
          icon:'none',
          title:'请输入正确的手机号'
        })
      }
    },
    setTime(){
      const a = setInterval(()=>{
        this.num--
        if(this.num == 0) {
          clearInterval(a)
          this.await = false
          this.num = 60
        }
      },1000)
    },
    onLogin(){
      if(!this.code || this.code.length !== 6){
        uni.showToast({
          icon:'none',
          title:'验证码不正确'
        })
        return
      }
      uni.request({
        url:`${NEW_BASE_URL}/api/app/login/smsLogin?mobile=${this.mobile}&code=${this.code}`,
        method:'GET',
        success:(resX)=>{
			console.log(resX)
          let res = resX.data
          if(res.code == 1){
            let userinfo = res.data.user
            uni.setStorageSync("hasDerivative",res.data.hasDerivative)
            uni.setStorageSync("userinfo", userinfo)
            uni.setStorageSync("UId", userinfo.id)
            uni.setStorageSync("token", res.data.token)
            uni.setStorageSync("isLogin", true)
            uni.setStorageSync("mobile", userinfo.mobile)
            uni.setStorageSync("qcode", userinfo.qcode)
            uni.setStorageSync("opents", 1)
            uni.setStorageSync("InvitationCode", res.data.user.invitationCode);
            uni.showToast({
              icon:'none',
              title:'登录成功'
            })
            const a = setTimeout(()=>{
              uni.switchTab({
                url:'/pages/index/index'
              })
              clearTimeout(a)
            },1000)
          }else{
            uni.showToast({
              icon:'none',
              title:res.msg
            })
          }
        }
      })
      // this.$http('common.smsLogin',{
      //   mobile: this.mobile,
      //   code:this.code
      // })
      //     .then(res=>{
      //       console.log(res)
      //     })
      // console.log('登录')

    },
    toWeb(e){
      this.$Router.push({
        path: '/pages/public/webview',
        query: {
          webviewPath: e == 1 ? 'https://www.hzwltb69.com/article/detail/14_0' : 'https://www.hzwltb69.com/article/detail/40_0'
        }
      })
    }
  }
}
</script>
<template>
  <view class="content"  style="background-color: #f9f9f9;">
    <view class="big-box">
      <view class="img-box">
        <image src="https://image.hzwltb69.com/app/date/2023/图片 1767.png"
        class="ljshop-image"
        ></image>
      </view>
      <view class="title">欢迎来到69商城</view>
      <view class="subTitle">未注册验证通过后将自动注册</view>
      <view class="phone-box">
        <view class="code-box">
          <view class="code">手机号</view>
          <view class="u-flex input-box">
            <view style="margin-right: 20rpx;">+86</view>
            <input style="flex: 1;" v-model.number="mobile" placeholder="请输入手机号"></input>
          </view>
        </view>
        <view class="code-box">
          <view class="code">验证码</view>
          <view class="u-flex input-box">
            <input  v-model="code" placeholder="请输入验证码"></input>
            <view v-if="!await" class="getCode" @click="getCode">获取验证码</view>
            <view class="getCode" style="color: #6C6C6C" v-else>{{num}}秒后重新获取</view>
          </view>
        </view>
      </view>
      <view class="loginbox"
      @click="onLogin"
      >登&nbsp;录</view>
      <view style="display: flex;align-items: center;"
      <!-- #ifdef MP-WEIXIN -->
	  :style="'margin-top: 200rpx'">
	  <!-- #endif -->
	  <!-- #ifdef APP-PLUS -->
	  :style="'margin-top: 100rpx'">
	  <!-- #endif -->
	  
        <u-checkbox-group>
          <u-checkbox
              activeColor="#922d23"
              shape="circle"
              v-model="item.checked"
              v-for="(item, index) in list" :key="index"
          ></u-checkbox>
        </u-checkbox-group>
        <span class="tip">
        同意
          <span style="color: #0f98f9" @click="toWeb(1)">用户服务协议</span>
          和
          <span style="color: #0f98f9" @click="toWeb(2)">隐私政策条件</span>
        </span>
      </view>
    </view>
  </view>
</template>
<style lang="scss" scoped>
.content{
  display: flex;
  max-height: 100vh;
  justify-content: center;
  //align-items: center;
  padding-top: 150rpx;
  .big-box{
    width: 680rpx;
    //background: red;
    display: flex;
    flex-direction: column;
  }
  .img-box{
    width: 125rpx;
    height: 125rpx;
    border-radius: 20rpx;
    overflow: hidden;
  }
  .title{
    margin-top: 35rpx;
    font-size: 45rpx;
    //font-weight: 600;
  }
  .subTitle{
    font-size: 24rpx;
    color: #afafaf;
  }
  .phone-box{
    margin-top: 50rpx;
    .code{
      font-size: 35rpx;
      margin-bottom: 20rpx;
    }
    .code-box{
      margin-bottom: 40rpx;
    }
    .input-box{
      padding-bottom: 20rpx;
      border-bottom: 1rpx solid #f6f6f6;
    }
    .getCode{
      font-size: 28rpx;
      color: #0f98f9;
      margin-left: 50rpx;
    }
  }
  .loginbox{
    width: 90%;
    height: 90rpx;
    background: linear-gradient(90deg,#d66d60 0%,#ac3328 100%);
    border-radius: 20rpx;
    line-height: 90rpx;
    text-align: center;
    font-size: 30rpx;
    margin-left: 5%;
    color: #fff;
    margin-top: 50rpx;
  }
  .tip{
    color:rgba(121, 121, 121, 1);
    font-size: 28rpx;
  }
}
::v-deep .u-checkbox{
  display: block !important;
  margin-right: 10rpx;
}

</style>